#!/bin/sh

# Slackware build script for mod_hosts_access (libwrap support in Apache)
# Written by Menno E. Duursma

PRGNAM=mod_hosts_access
VERSION=1.1.0
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=`pwd`		
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP 
rm -rf $PRGNAM-$VERSION
tar -xzvf $CWD/$PRGNAM-$VERSION.tar.gz || exit 1
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R a-s,u+w,go+r-w .

if [ ! -z CFLAGS ]; then
  CFLAGS_OLD="${CFLAGS}"
  CFLAGS="$SLKCFLAGS"
else
  CFLAGS_WASSET=no
  export CFLAGS
fi

# Compile module as DSO (dynmically shared object)
apxs -ca mod_hosts_access.c -lwrap -lnsl

# Restore compiler flags
if [ -z CFLAGS_WASSET ]; then
  unset CFLAGS
else
  CFLAGS="${CFLAGS_OLD}"
fi

# Strip binary
strip mod_hosts_access.so

# Create target dir, copy module into place
mkdir -p $PKG/usr/libexec/apache
cp mod_hosts_access.so $PKG/usr/libexec/apache

# Copy program documentation into the package, including this script
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a [A-Z]* $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz

# Clean up the extra stuff
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/$PRGNAM-$VERSION
  rm -rf $PKG
fi
